<?php

/**
 * 测试接口,并无实际用途
 */

require_once './application/third_party/qiniu/autoload.php';

use Qiniu\Auth;
use Qiniu\Storage\UploadManager;
class qiniu extends CI_Controller
{


    public function upload($filePath,$key){
        // 用于签名的公钥和私钥
        $accessKey = 'WFL-Yl8a1WoQt0UfqWfQxpgly2Xyd9LwOlb5XXmh';
        $secretKey = 'QQWPYIA89JZe9JBBAaVRJgGski0srg-WY2Fjg9rI';

        // 空间名  https://developer.qiniu.io/kodo/manual/concepts
        $bucket = 'procurement';

        // 初始化签权对象
        $auth = new Auth($accessKey, $secretKey);

        // 生成上传 Token
        $token = $auth->uploadToken($bucket);

        // 要上传文件的本地路径
//        $filePath = $_FILES['test']['tmp_name'];


        // 上传到七牛后保存的文件名
//        $key = 'my-php-2233logo.png';
        // 初始化 UploadManager 对象并进行文件的上传
        $uploadMgr = new UploadManager();
        // 调用 UploadManager 的 putFile 方法进行文件的上传
        list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);

        return $err;
        echo "\n====> putFile result: \n";
        if ($err !== null) {
            var_dump($err);
        } else {
            var_dump($ret);
        }



    }



}










































